package com.youyi.yyfilepickerlibrary.core.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.lkx.liandianqinew.R;
import com.youyi.yyfilepickerlibrary.core.model.Album;

public class BuketAdapter extends CursorAdapter {
    private final Drawable mPlaceholder;

    public BuketAdapter(Context context, Cursor cursor, boolean z) {
        super(context, cursor, z);
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(new int[]{R.attr.album_thumbnail_placeholder});
        this.mPlaceholder = obtainStyledAttributes.getDrawable(0);
        obtainStyledAttributes.recycle();
    }

    public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
        return LayoutInflater.from(context).inflate(R.layout.buket_list_item, viewGroup, false);
    }

    public void bindView(View view, Context context, Cursor cursor) {
        Album valueOf = Album.valueOf(cursor);
        ((TextView) view.findViewById(R.id.album_name)).setText(valueOf.getDisplayName(context));
        ((TextView) view.findViewById(R.id.album_media_count)).setText(String.valueOf(valueOf.getCount()));
        Glide.with(context).load(valueOf.getCoverPath()).apply(new RequestOptions().centerCrop().placeholder(this.mPlaceholder)).into((ImageView) view.findViewById(R.id.album_cover));
    }
}
